//package com.eastfair.gateway.filters;
//
//import cn.hutool.core.util.IdUtil;
//import com.eastfair.core.context.ContextConstants;
//import org.slf4j.MDC;
//import org.springframework.cloud.gateway.filter.GatewayFilterChain;
//import org.springframework.cloud.gateway.filter.GlobalFilter;
//import org.springframework.core.Ordered;
//import org.springframework.http.server.reactive.ServerHttpRequest;
//import org.springframework.stereotype.Component;
//import org.springframework.web.server.ServerWebExchange;
//import reactor.core.publisher.Mono;
//
///**
// * 生成日志链路追踪id，并传入header中
// *
// * @author ligang
// * @date 2021年08月02日18:02:47
// */
//@Component
//public class TraceFilter implements GlobalFilter, Ordered {
//
//    @Override
//    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
//        //生成链路追踪id
////        String traceId = IdUtil.fastSimpleUUID();
//        //存入MDC用于全局log缓存
////        MDC.put(ContextConstants.LOG_TRACE_ID, traceId);
//        //存入request header头信息
//        ServerHttpRequest serverHttpRequest = exchange.getRequest().mutate()
////                .headers(h -> h.add(ContextConstants.TRACE_ID_HEADER, traceId))
//                .build();
//
//        ServerWebExchange build = exchange.mutate().request(serverHttpRequest).build();
//        return chain.filter(build);
//    }
//
//    @Override
//    public int getOrder() {
//        return Ordered.HIGHEST_PRECEDENCE;
//    }
//}
